<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title></title>
    <link rel="stylesheet" type="text/css" href="${path}/css/main.css">
	<link rel="stylesheet" type="text/css" href="${path}/css/mainTable.css">
	<script type="text/javascript" language="javascript" src="${path}/js/calendar/js/WdatePicker.js"></script>
	<script type="text/javascript" language="javascript" src="${path}/js/jquery.js"></script>
	<script type="text/javascript" language="javascript" src="${path}/js/jquery.blockUI.js"></script>
	<script type="text/javascript">
		function check(){
			var time_begin = document.getElementById("time_begin").value;
			var time_end = document.getElementById("time_end").value;
			
			if(!isDate(time_begin)){
				alert("开始日期格式不对");
					return false;
				}
				if(!isDate(time_end)){
					alert("结束日期格式不对");
					return false;
				}
				
				var start = time_begin.replace(/\-/g,"/");
			var end = time_end.replace(/\-/g,"/");
				if(Date.parse(start) > Date.parse(end)){
				alert("结束日期不能小于开始日期!");
	    		return false;
			}
			$.blockUI({message: '正在查询...' });
		}
		
		function isDate(vDate){
			var regular = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
			var isMatch = vDate.match(regular);
			if(!isMatch){
				return false;
			}
			var date = new Date(isMatch[1],isMatch[3]-1,isMatch[4]);
			
			return (date.getFullYear()==isMatch[1]&&date.getMonth()==isMatch[3]-1&&date.getDate()==isMatch[4]);
		}
		
		/**导出业务结算信息*/
		function exportAnalsisProvince(){
			var time_begin = document.getElementById("time_begin").value;
			var time_end = document.getElementById("time_end").value;
			
			if(!isDate(time_begin)){
				alert("开始日期格式不对");
  				return false;
  			}
  			if(!isDate(time_end)){
  				alert("结束日期格式不对");
  				return false;
  			}
  			
  			var start = time_begin.replace(/\-/g,"/");
			var end = time_end.replace(/\-/g,"/");
  			if(Date.parse(start) > Date.parse(end)){
    			alert("结束日期不能小于开始日期!");
        		return false;
    		}
  			
    		$("#provinceAnalysisForm").attr("action", "${path }/analysis/exportAnalsisProvince.action");
    		$("#provinceAnalysisForm").attr("method","post");
    		$("#provinceAnalysisForm").submit();
    		$("#provinceAnalysisForm").attr("action", "${path }/analysis/getProvinceAnalysis.action");
		}
		
	</script>
  </head>
  
  <body>
    <div>
    	<form id="provinceAnalysisForm" name="provinceAnalysisForm" method="post" action="${path }/analysis/getProvinceAnalysis.action" onsubmit="return check();">
    		<p>分省数据</p>
    		渠<span style="font-family:'Times New Roman';">&nbsp;</span>道<span style="font-family:'Times New Roman';">&nbsp;</span>名<span style="font-family:'Times New Roman';">&nbsp;</span>称<span style="font-family:'Times New Roman';">&nbsp;</span>:
    		<select id="lower_id" name="term.lower_id">
    			<option value="0">全部</option>
    			<c:if test="${partnerLowerVoList != null && fn:length(partnerLowerVoList) > 0 }">
    				<c:forEach var="partnerLowerVo" items="${partnerLowerVoList }" varStatus="list">
    					<option value="${partnerLowerVo.id }" <c:if test="${partnerLowerVo.id eq term.lower_id }">selected</c:if>>${partnerLowerVo.name }</option>
    				</c:forEach>
    			</c:if>
    		</select>
    		<br />
    		业务长号码:
    		<select id="gateway_id" name="term.gateway_id">
    			<option value="0">全部</option>
    			<c:if test="${gatewayVoList != null && fn:length(gatewayVoList) > 0}">
    				<c:forEach var="gatewayVo" items="${gatewayVoList }" varStatus="list">
    					<option value="${gatewayVo.id }" <c:if test="${gatewayVo.id eq term.gateway_id }">selected</c:if>>${gatewayVo.sp_number }</option>
    				</c:forEach>
    			</c:if>
    		</select>
    		<br />
    		开<span style="font-family:'Times New Roman';">&nbsp;</span>始<span style="font-family:'Times New Roman';">&nbsp;</span>日<span style="font-family:'Times New Roman';">&nbsp;</span>期<span style="font-family:'Times New Roman';">&nbsp;</span>:
    		<input type="text" id="time_begin" name="term.time_begin" value="${term.time_begin }" class="Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,readOnly:true})" size="10" maxlength="10" readonly="readonly" />
    		<br />
    		结<span style="font-family:'Times New Roman';">&nbsp;</span>束<span style="font-family:'Times New Roman';">&nbsp;</span>日<span style="font-family:'Times New Roman';">&nbsp;</span>期<span style="font-family:'Times New Roman';">&nbsp;</span>:
    		<input type="text" id="time_end" name="term.time_end" value="${term.time_end }" class="Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,readOnly:true})" size="10" maxlength="10" readonly="readonly" />
    		<input type="submit" name="query" value="查询" />
    		<input type="button" name="export" value="导出" onclick="exportAnalsisProvince();" />
    		<input type="hidden" name="exportName" value="分省数据.xls">
    		
    		<table>
    			<thead>
    				<tr>
    					<th>省份</th>
    					<th>计费数量</th>
    					<th>同步数量</th>
    					<th>过滤数量</th>
    					<th>计费时长（分）</th>
    					<th>同步时长（分）</th>
    					<th>过滤时长（分）</th>
    					<th>总收入（元）</th>
    					<th>同步收入（元）</th>
    					<th>过滤收入（元）</th>
    				</tr>
    			</thead>
    			<c:choose>
    				<c:when test="${analysisVoList != null && fn:length(analysisVoList) > 0}">
    					<c:forEach var="analysisVo" items="${analysisVoList }" varStatus="list">
    						<tr style="${list.index%2 != 0 ? 'background-color: #fea;' : 'background-color: #fff;' }">
    							<td>${analysisVo.province }</td>
    							<td>${analysisVo.fee_user_num_sum }</td>
    							<td>${analysisVo.fee_user_num }</td>
    							<td>${analysisVo.fee_user_num_filter }</td>
    							<td>${analysisVo.fee_minute_sum }</td>
    							<td>${analysisVo.fee_minute }</td>
    							<td>${analysisVo.fee_minute_filter }</td>
    							<td>${analysisVo.fee_price_sum }</td>
    							<td>${analysisVo.fee_price }</td>
    							<td>${analysisVo.fee_price_filter }</td>
    						</tr>
    						<c:set var="fee_user_num_sum_count" value="${fee_user_num_sum_count + analysisVo.fee_user_num_sum }"></c:set>
    						<c:set var="fee_user_num_count" value="${fee_user_num_count + analysisVo.fee_user_num  }"></c:set>
    						<c:set var="fee_user_num_filter_count" value="${fee_user_num_filter_count + analysisVo.fee_user_num_filter }"></c:set>
    						<c:set var="fee_minute_sum_count" value="${fee_minute_sum_count + analysisVo.fee_minute_sum }"></c:set>
    						<c:set var="fee_minute_count" value="${fee_minute_count + analysisVo.fee_minute }"></c:set>
    						<c:set var="fee_minute_filter_count" value="${fee_minute_filter_count + analysisVo.fee_minute_filter }"></c:set>
    						<c:set var="fee_price_sum_count" value="${fee_price_sum_count + analysisVo.fee_price_sum }"></c:set>
    						<c:set var="fee_price_count" value="${fee_price_count + analysisVo.fee_price }"></c:set>
    						<c:set var="fee_price_filter_count" value="${fee_price_filter_count + analysisVo.fee_price_filter }"></c:set>
    					</c:forEach>
    					<tr style="${fn:length(analysisVoList)%2 != 0 ? 'background-color: #fea;' : 'background-color: #fff;' }">
    						<td>总计</td>
    						<td>${fee_user_num_sum_count }</td>
    						<td>${fee_user_num_count }</td>
    						<td>${fee_user_num_filter_count }</td>
    						<td>${fee_minute_sum_count }</td>
    						<td>${fee_minute_count }</td>
    						<td>${fee_minute_filter_count }</td>
    						<td>${fee_price_sum_count }</td>
    						<td>${fee_price_count }</td>
    						<td>${fee_price_filter_count }</td>
    					</tr>
    				</c:when>
    				<c:otherwise>
    					<tr>
    						<td>请选择条件查询</td>
    					</tr>
    				</c:otherwise>
    			</c:choose>
    		</table>
    	</form>
    </div>
  </body>
</html>